import axios from 'axios';
import qs from 'query-string';

export interface Record {
  id?: number;
  img: string;
  price: number;
  original_price: number;
  stock: number;
  title: string;
  imgs: string;
  shipping_address: string;
  goods_type_id: string;
  sold: number;
  type: boolean;
  norm: string;
  norm_arr: string;
  status: boolean;
  courier_fee: number;
  params: string;
  content: string;
  sort: number;
  recommend: 1 | 2 | 3;
  synopsis: string;
  keyword: string;
  unit: string;
  createtime?: number;
  updatetime?: number;
}

export interface Params extends Partial<any> {
  current: number;
  pageSize: number;
}

export interface Res {
  list: Record[];
  total: number;
}

export function getData(params: Params) {
  return axios.get<Res>('/pc/score_goods/list', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}

export function savetData(data: any) {
  return axios({
    url: '/pc/score_goods/save',
    method: 'post',
    data,
  });
}

export function delData(ids: string | number) {
  return axios({
    url: '/pc/score_goods/del',
    method: 'delete',
    data: { ids },
  });
}

export function changeData(data: any) {
  return axios({
    url: '/pc/score_goods/change',
    method: 'post',
    data,
  });
}
